package com.ruoyi.common.utils;

import com.alibaba.fastjson.JSON;

public class JsonBeanUtil {
	public static Object transJson2Bean(String jsonStr, Class<?> objectClass) {

		Object o = null;
		 
		try {  
			o = JSON.parseObject(jsonStr, objectClass); 
        } catch (Exception e) {  
            System.out.println("transMap2Bean2 Error " + e);  
        }  
		
		return o;
    }

	//by 泛型
	public static <T> T transJson2Obj(String jsonStr, Class<T> objectClass) {

		T o = null;

		try {
			o = JSON.parseObject(jsonStr, objectClass);
		} catch (Exception e) {
			System.out.println("transJson2Obj Error " + e);
		}

		return o;
	}

	public static String transBean2Json(Object o) {  

		String jsonStr = "";
		
		try {  
			jsonStr = JSON.toJSONString(o);
        } catch (Exception e) {  
            System.out.println("transMap2Bean2 Error " + e);  
        }  
		
		return jsonStr;
    }  
	
}
